package heima3_2.cn.osc.presenter.event_recent_presenter;

import android.content.Context;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import java.util.List;

import heima3_2.cn.osc.constant.Constants;
import heima3_2.cn.osc.model.bean.EventBean;
import heima3_2.cn.osc.model.bean.MoveMyBean;
import heima3_2.cn.osc.presenter.BasePresenter;
import heima3_2.cn.osc.ui.main_fragment.event_particulars_fragment.ExeriseRecentFragment;
import heima3_2.cn.osc.utils.PreferencesUtils;
import retrofit2.Call;
import retrofit2.Response;

/**
 * Created by Administrator on 2017/1/18 0018.
 */

public class ExerisePresenter extends BasePresenter<MoveMyBean> {
    private  Context mContext;
    private ExeriseRecentFragment mExeriseRecentFragment;
   // private MoveDetailBean.PostBean mPost;

    public ExerisePresenter(Context context, ExeriseRecentFragment eventRecentFragment){
        this.mExeriseRecentFragment=eventRecentFragment;
        this.mContext=context;
    }
    @Override
    protected void getFailureData(Throwable t) {
            t.printStackTrace();
    }

    @Override
    protected void getSuccessData(Response<MoveMyBean> response) {
        MoveMyBean body = response.body();
        List<EventBean> events = body.getEvents();
        EventBean eventBean = events.get(0);
        mExeriseRecentFragment.mWvParticulars.loadUrl(eventBean.getUrl());
        mExeriseRecentFragment.mWvParticulars.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String request) {
                view.loadUrl(request);
                return super.shouldOverrideUrlLoading(view, request);
            }
        });

    }

    @Override
    public void getData(int page) {
        int newsID = PreferencesUtils.getInt(mContext, Constants.EXERISE_ID);
        System.out.println("newsID"+newsID);
        if(newsID!=0){
            Call<MoveMyBean> info = mRetrofitInterface.getExerise();
            info.enqueue(mCallback);

        }
    }
}
